﻿Public Class generatenum
    Public Shared Function GenerateNo() As String

        Dim obj As Object = CMD.ExecuteScalar("SELECT MAX(EMP_CODE) FROM TBL_EMPLOYEE;")
        Dim lastNo As String
        If obj Is DBNull.Value Then
            lastNo = "EMP-0000000"
        Else
            lastNo = obj.ToString()
        End If

        ' PUC-000031
        lastNo = lastNo.Replace("EMP-", "")
        ' 000031
        Dim nextNo As Int16 = Convert.ToInt16(lastNo) + 1
        ' 32
        Dim result = "EMP-" & nextNo.ToString("000000")
        Return result

    End Function
End Class
